package com.workflow.workflowproject.controller;

import com.workflow.workflowproject.entity.FlowInfo;
import com.workflow.workflowproject.service.FlowInfoService;
import com.workflow.workflowproject.tools.Result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Tag(name = "流程信息")
@RequestMapping("/flowInfo")
public class FlowInfoController {

    @Autowired
    private FlowInfoService flowInfoService;

    /**
     * 添加流程信息
     *
     * @param
     * @return
     */
    @PostMapping
    @Operation(summary="添加流程信息",description="添加流程信息")
    public Result addFlowInfo(@RequestBody FlowInfo flowInfo) throws Exception{
        return flowInfoService.addFlowInfo(flowInfo);
    }

    /**
     * 修改流程信息
     *
     * @param
     * @return
     */
    @PutMapping("/{id}")
    @Operation(summary="修改流程信息",description="修改流程信息")
    public Result updateFlowInfo(@PathVariable Integer id, @RequestBody FlowInfo flowInfo) throws Exception{
        return flowInfoService.updateFlowInfo(id,flowInfo);
    }

    /**
     * 删除流程信息
     *
     * @param
     * @return
     */
    @DeleteMapping("/{id}")
    @Operation(summary="删除流程信息",description="删除流程信息")
    public Result deleteFlowInfo(@PathVariable Integer id) throws Exception{
        return flowInfoService.deleteFlowInfo(id);
    }
    /**
     * 根据id查询流程信息
     *
     * @param
     * @return
     */
    @GetMapping("/{id}")
    @Operation(summary="根据id查询流程信息",description="根据id查询流程信息")
    public Result getFlowInfoById(@PathVariable Integer id) throws Exception{
        return flowInfoService.getFlowInfoById(id);
    }
    /**
     * 查询所有流程信息
     *
     * @param
     * @return
     */
    @GetMapping
    public Result getAllFlowInfo() throws Exception{
        return flowInfoService.getAllFlowInfo();
    }
    /**
     * 分页查询流程条件
     *
     * @param
     * @return
     */
    @GetMapping("/page")
    public Result getFlowInfoPage(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                 @RequestParam(value = "limit", defaultValue = "10") Integer limit) throws Exception{
        return flowInfoService.getFlowInfoPage(page,limit);
    }
}
